package com.whfc.gas.codec;

import com.whfc.gas.entity.GasMsg;
import com.whfc.gas.util.GasMsgUtil;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageEncoder;

import java.util.List;

public class GasMsgEncoder extends MessageToMessageEncoder<GasMsg> {

    @Override
    protected void encode(ChannelHandlerContext channelHandlerContext, GasMsg outMsg, List<Object> out) throws Exception {
        ByteBuf buf = Unpooled.buffer(outMsg.getLength() + 2);
        GasMsgUtil.encode(outMsg, buf);
        out.add(buf);
    }
}
